package com.haiyou.dc.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeTool {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");

    public interface Task {
        void execute();
    }

    public static void check(String title, Task task) {
        System.out.println(String.format("[%s]", title));
        System.out.println(String.format("开始：%s", sdf.format(new Date())));
        long begin = System.currentTimeMillis();
        task.execute();
        long end = System.currentTimeMillis();
        System.out.println(String.format("结束：%s", sdf.format(new Date())));
        System.out.println(String.format("耗时：%s 秒", (end - begin) / 1000));
    }

    public static void main(String[] args) {
        check("test",()->{
            System.out.println("xxx");
        });
    }
}
